package net.lbh.share;


import com.umeng.socialize.bean.SHARE_MEDIA;

import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.text.TextUtils;

/**
 * 
 * @author BaoHong.Li
 * @date 2015-7-23 上午10:13:09
 * @update (date)
 * @version V1.0
 */
public class ConstantKeys {

	public static boolean isInitQQKeys;
	public static boolean isInitWxKeys;
	public static boolean isInitSinaKeys;
	public static boolean isInitRRKeys;
	public static boolean isInitYxKeys;
	public static boolean isInitTENCENTKeys;
	public static boolean isInitDOUBANKeys;

	private static final String TAG = ConstantKeys.class.getName();

	/** qq 开发平台app id */
	public static String QQ_APP_ID = "";
	/** qq 开发平台app key */
	public static String QQ_APP_KEY = "";

	/** 微信 app id */
	public static String WX_APP_ID = "wx79e95c3cb4556117";
	/** 微信 app secret */
	public static String WX_APP_SECRET = "9fb6b72c78484ac5e4f7785d783f59a2";

	/** 易信 app id */
	public static String YX_APP_ID = "";

	/** 人人 开发平台app key */
	public static String RR_APP_KEY = "";
	/** 人人 开发平台app secret */
	public static String RR_APP_SECRET = "";

	private ConstantKeys() {
	}

	// 在application应用<meta-data>元素。
	public static String getMetaData(Activity activity, String key) {

		ApplicationInfo appInfo = null;
		String value = "";
		try {
			appInfo = activity.getPackageManager().getApplicationInfo(
					activity.getPackageName(), PackageManager.GET_META_DATA);
			value = String.valueOf(appInfo.metaData.get(key));
			L.d(TAG, "meta-data :key: " + key);
			L.d(TAG, "  meta-data :value: " + value);
		} catch (NameNotFoundException e) {
			L.w(TAG, e.getMessage());
		}

		return value;
	}

	public static boolean initQQKeys(String appId, String appKey) {
		
		if (ConstantKeys.isInitQQKeys) {
			return true;
		}
		if (TextUtils.isEmpty(appId) ||TextUtils.isEmpty(appKey) ) {
			isInitQQKeys = false;
			return false;
		}
		ConstantKeys.QQ_APP_ID = appId;
		ConstantKeys.QQ_APP_KEY = appKey;
		isInitQQKeys = true;
		return true;
	}

	/**
	 * 初始化 微信 配置参数
	 * 
	 * @param partnerId
	 * @param mchId
	 * @param privateKey
	 * @param publicKey
	 * @return boolean
	 * @autour BaoHong.Li
	 * @date 2015-7-17 上午9:58:46
	 * @update (date)
	 */
	public static boolean initWxKeys(String appId, String appSecret) {
		if (ConstantKeys.isInitWxKeys) {
			return true;
		}
		
		if (TextUtils.isEmpty(appId) ||TextUtils.isEmpty(appSecret) ) {
			isInitQQKeys = false;
			return false;
		}
		ConstantKeys.WX_APP_ID = appId;
		ConstantKeys.WX_APP_SECRET = appSecret;
		isInitWxKeys = true;
		return true;

	}

	/**
	 *
	 * 初始化 人人 平台 配置参数
	* @param appkey
	* @param appSecret
	* @return boolean
	* @throws
	* @autour BaoHong.Li
	* @date 2015-7-23 上午11:49:31 
	* @update (date)
	 */
	public static boolean initRRKeys(String appkey, String appSecret) {
		if (ConstantKeys.isInitRRKeys) {
			return true;
		}
		
		if (TextUtils.isEmpty(appkey) ||TextUtils.isEmpty(appSecret) ) {
			isInitRRKeys = false;
			return false;
		}
		ConstantKeys.RR_APP_KEY = appkey;
		ConstantKeys.RR_APP_SECRET = appSecret;
		isInitRRKeys = true;
		return true;
		
	}

	/**
	 *
	 * 初始化 易信  平台 配置参数
	* @param appId
	* @return boolean
	* @autour BaoHong.Li
	* @date 2015-7-23 上午11:52:42 
	* @update (date)
	 */
	public static boolean initYxKeys(String appId) {
		if (ConstantKeys.isInitYxKeys) {
			return true;
		}
		
		if (TextUtils.isEmpty(appId) ) {
			isInitYxKeys = false;
			return false;
		}
		ConstantKeys.YX_APP_ID = appId;
		isInitYxKeys = true;
		return true;
		
	}

	/**
	 *
	 * 初始化 腾讯微博 keys
	* @param appId
	* @param appSecret
	* @return boolean
	* @throws
	* @autour BaoHong.Li
	* @date 2015-7-23 上午11:05:14 
	* @update (date)
	 */
	public static boolean initTencentKeys(String appId, String appSecret) {
		ConstantKeys.WX_APP_ID = appId;
		ConstantKeys.WX_APP_SECRET = appSecret;
		isInitWxKeys = true;
		return true;
		
	}

	/**
	 * 
	 * 检查是否已经 初始化 keys
	 * 
	 * @return void
	 * @autour BaoHong.Li
	 * @date 2015-7-23 上午10:27:26
	 * @update (date)
	 */
	public static boolean verifyInitKeys(SHARE_MEDIA platform) {

		switch (platform) {

		// qq
		case QQ:
		case QZONE:
			
			return isInitQQKeys;

			// 微信
		case WEIXIN:
		case WEIXIN_CIRCLE:

			return isInitWxKeys;

			// 人人
		case RENREN:

			return isInitQQKeys;

			// 腾讯微博
		case TENCENT:

			return isInitTENCENTKeys =true;  //默认没有初始化 参数
			// 新浪微博
		case SINA:

			return isInitSinaKeys =true;  //默认没有初始化 参数

		case DOUBAN:

			return isInitDOUBANKeys;

		default:
			return true;

		}

	}

}
